import request from "@/utils/request";
import type { PermissionResponseData, MenuParams } from "./type";

enum API {
  // 获取菜单与按钮标识数据
  ALLPERMISSTION_URL = "/admin/acl/permission",
  //给某一级菜单新增子菜单
  ADDMENU_URL = "/admin/acl/permission/save",
  // 修改菜单
  UPDATEMENU_URL = "/admin/acl/permission/update",
  //   删除菜单
  DELETEMENU_URL = "/admin/acl/permission/remove/",
}

// 获取菜单数据
export const reqAllPermisstion = () =>
  request.get<any, PermissionResponseData>(API.ALLPERMISSTION_URL);

// 新增菜单或者修改菜单
export const reqAddOrUpdateMenu = (data: MenuParams) => {
  if (data.id) {
    // 更新
    return request.put<any, any>(API.UPDATEMENU_URL, data);
  } else {
    // 新增
    return request.post<any, any>(API.ADDMENU_URL, data);
  }
};

// 删除菜单
export const reqRemoveMenu = (id: number) =>
  request.delete<any, any>(API.DELETEMENU_URL + id);
